package com.lyj.ai.controller;

import org.springframework.ai.image.ImagePrompt;
import org.springframework.ai.image.ImageResponse;
import org.springframework.ai.openai.OpenAiImageModel;
import org.springframework.ai.openai.OpenAiImageOptions;
import org.springframework.ai.openai.api.OpenAiImageApi;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 *图像生成
 */
@RestController
public class ImgController {


    @Autowired
    OpenAiImageModel openAiImageModel;


    @RequestMapping("/ai/img")
    public String img() {
        ImageResponse response = openAiImageModel.call(
                new ImagePrompt("猫在抓老鼠",
                        OpenAiImageOptions.builder()
                                .withModel(OpenAiImageApi.DEFAULT_IMAGE_MODEL)
                                .quality("hd")
                                .N(4)
                                .height(1024)
                                .width(1024).build())
        );
        return response.getResult().getOutput().getUrl().toString();
    }
}
